Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

debounce-promise

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

debounce-promise

Create a debounced version of a promise returning function

  • 3.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is debounce-promise?

The debounce-promise npm package is used to debounce promises, ensuring that a function is not called too frequently. This is particularly useful in scenarios where you want to limit the rate at which a function is executed, such as in search input fields or API calls.

What are debounce-promise's main functionalities?

Basic Debouncing

This feature allows you to debounce a function that returns a promise. In this example, the fetchData function is debounced with a delay of 300 milliseconds. This means that if fetchData is called multiple times within 300 milliseconds, it will only execute once.

const debounce = require('debounce-promise');
const fetchData = () => fetch('https://api.example.com/data');
const debouncedFetchData = debounce(fetchData, 300);

debouncedFetchData().then(response => response.json()).then(data => console.log(data));

Leading Edge Execution

This feature allows the debounced function to be executed immediately on the leading edge of the timeout, rather than waiting for the delay to pass. In this example, fetchData is executed immediately the first time it is called, and then debounced for subsequent calls.

const debounce = require('debounce-promise');
const fetchData = () => fetch('https://api.example.com/data');
const debouncedFetchData = debounce(fetchData, 300, { leading: true });

debouncedFetchData().then(response => response.json()).then(data => console.log(data));

Trailing Edge Execution

This feature ensures that the debounced function is executed at the trailing edge of the timeout. In this example, fetchData will be executed after the 300 milliseconds delay if no new calls are made within that period.

const debounce = require('debounce-promise');
const fetchData = () => fetch('https://api.example.com/data');
const debouncedFetchData = debounce(fetchData, 300, { trailing: true });

debouncedFetchData().then(response => response.json()).then(data => console.log(data));

Other packages similar to debounce-promise

Keywords

FAQs

Package last updated on 05 May 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc